package com.probiz.estore.common.model.catalog;

import org.apache.commons.lang.StringUtils;

import com.probiz.estore.common.model.catalog.base.GiftCategoryTbl;

/**
 * Model class for GiftCategory. Add not database mapped fileds in this class.
 */
public class GiftCategory extends GiftCategoryTbl {
	public final static Short	STATUS_ACTIVE			= (short) 1;
	public final static Short	STATUS_INACTIVE			= (short) 0;
	public final static Short	STATUS_DELETED			= (short) -1;
	public final static Integer	SORTORDER_DEFAULT_VALUE	= new Integer("9999");
	public final static Integer	ROOT_ID					= new Integer("1");	// 根目录id

  	/**
	 * Default Empty Constructor for class GiftCategory
	 */
	public GiftCategory () {
		super();
	}
	/**
	 * 定义实体的业务名取值； giftCategoryName
	 * 必须手工完成这个部分，否则编译不通过。
	 */
	public String getGiftCategoryName () {
		if (this.categoryId == null)
	        return "";
	    else
			//返回一个指定有业务意义的属性值;
			//如：product的VO就用product.productName
	        return this.categoryId.toString();
	}
	/**
	 * Default Key Fields Constructor for class GiftCategory
	 */
	public GiftCategory (
		 Integer in_categoryId
		) {
		super (
		  in_categoryId
		);
	}

	/**
	 * 获取完整的目录路径名 例：主页>电器>冰箱>海尔冰箱
	 * 
	 * @return 完整的目录路径名
	 */
	public String getFullCategoryPathName() {
		if (StringUtils.isNotBlank(getParentFullCategoryPathName())) {
			return getParentFullCategoryPathName() + ">" + getCategoryName();
		} else {
			return getCategoryName();
		}
	}

	/**
	 * 获取简单的目录路径名(不包含根) 例：电器>冰箱>海尔冰箱
	 * 
	 * @return 简单的目录路径名(不包含根)
	 */
	public String getSimpleCategoryPathName() {
		StringBuffer categoryPathNameBuffer = new StringBuffer(100);
		GiftCategory parentCategory = this.getParent();
		while (parentCategory != null && parentCategory.getCategoryId() != 1) {
			categoryPathNameBuffer.insert(0, ">");
			categoryPathNameBuffer.insert(0, parentCategory.getCategoryName());
			parentCategory = parentCategory.getParent();
		}
		String categoryPathName = categoryPathNameBuffer.toString();
		if (!StringUtils.isEmpty(categoryPathName))
			categoryPathName = categoryPathName.substring(0, categoryPathName
					.length() - 1);
		if (StringUtils.isBlank(categoryPathName)) {
			return getCategoryName();
		} else {
			return categoryPathName + ">" + getCategoryName();
		}
	}

	/**
	 * 获取父目录完整的目录路径名 例：主页>电器>冰箱
	 * 
	 * @return 父目录完整的目录路径名
	 */
	public String getParentFullCategoryPathName() {
		StringBuffer categoryPathNameBuffer = new StringBuffer(100);
		GiftCategory parentCategory = this.getParent();
		while (parentCategory != null) {
			categoryPathNameBuffer.insert(0, ">");
			categoryPathNameBuffer.insert(0, parentCategory.getCategoryName());
			parentCategory = parentCategory.getParent();
		}
		String categoryPathName = categoryPathNameBuffer.toString();
		if (!StringUtils.isEmpty(categoryPathName))
			categoryPathName = categoryPathName.substring(0, categoryPathName
					.length() - 1);
		return categoryPathName;
	}

}
